/*
 * Created by Jaren at 2021/10/29 14:05
 */
import 'dart:typed_data';

import 'package:inmotion_protocol/common/compact.dart';
import 'package:inmotion_protocol/common/product_model.dart';
import 'package:inmotion_protocol/common/product_version.dart';

abstract class Base<T> {
  Compact<Base<T>>? compact;
  VersionWrapper version;
  ProductModel model = ProductModel.unknown;

  Base(this.model, this.version) {
    initCompact();
  }

  void initCompact();

  void fromBytes(Uint8ClampedList bytes, int offset) {
    _checkCompact();
    compact!.fromBytes(this, bytes, offset);
  }

  int length() {
    _checkCompact();
    return compact!.length();
  }

  void _checkCompact() {
    assert(compact != null);
  }

  @override
  String toString() {
    return compact.runtimeType.toString() + ": " + compact.toString();
  }
}
